package cn.itcast.exception;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SaaSException implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
//       如果当前异常是 UnauthorizedException 那么就直接跳转到unauthorized.jsp
        ModelAndView mv = new ModelAndView();
        if(ex instanceof UnauthorizedException){ //判断ex具体的异常类是否是UnauthorizedException
            mv.setViewName("forward:/unauthorized.jsp"); //不走视图解析器
        }else{
            mv.addObject("errorMsg",ex.getMessage());
            mv.setViewName("error"); //逻辑视图
        }
        return mv;
    }
}
